﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/WithoutPermBasic.Master" AutoEventWireup="true" CodeBehind="InvoicePayInfo.aspx.cs" Inherits="PMS.UI.FM.InvoicePayInfo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        var height = $("#divTotal").height();
        var content = parseFloat(height) - 30;
        $("#tbList").css("height", content);

        method = com.get.method;
        invoiceID = com.get.Id;

        $(function () {
            if (method == "look") {
                $("a.easyui-linkbutton").linkbutton('disable')
            }

            //加载发票信息
            com.ajax({
                url: "/Logic/FM/InvoiceAjax.aspx?method=GetInvoiceById",
                data: { "Id": invoiceID },
                success: function (data) {
                    invoiceData = data;
                    $("#form1").form("load", data);
                }
            });

            //加载钩稽的回款信息
            $("#tbList").datagrid({
                url: '/Logic/FM/InvoicePayAjax.aspx?method=GetRPayListByInvID&InvoiceID=' + invoiceID,
                loadMsg: '数据加载中请稍后……',
                fitColumns: false,
                rownumbers: true,
                idField: "ID",
                singleSelect: true,
                striped: true,
                frozenColumns: [[
                    {
                        field: 'ck', checkbox: true, width: 30
                    },
                    {
                        field: 'ReceivePayID', title: '回款ID', align: 'center', width: 60, editor: {
                            type: "combogrid",
                            options: {
                                url: '/Logic/FM/ReceivePayAjax.aspx?method=GetAllReceivePay',
                                idField: 'ID',
                                textField: 'ID',
                                columns: [[
                                    {
                                        field: 'ID', title: 'ID', width: 60
                                    },
                                    {
                                        field: 'PayNo', title: '回款流水号', width: 120
                                    },
                                    {
                                        field: 'Money', title: '金额', width: 60
                                    },
                                    {
                                        field: 'Date', title: '回款日期', width: 120
                                    },
                                    {
                                        field: 'ComName', title: '回款客户', width: 120
                                    }
                                ]],
                                panelWidth: 500,
                                required: true,
                                onSelect: function (rowIndex, rowData) {
                                    var editors = $("#tbList").datagrid('getEditors', editRow);
                                    $(editors[1].target).textbox('setValue', rowData.PayNo);
                                    $(editors[4].target).textbox('setValue', rowData.Money);
                                    $(editors[5].target).textbox('setValue', rowData.Date);
                                    $(editors[6].target).textbox('setValue', rowData.State);
                                }
                            }
                        }
                    },
                    {
                        field: 'PayNo', title: '回款流水号', align: 'center', width: 120, editor: {
                            type: "textbox",
                            options: {
                                editable: false
                            }
                        }
                    },
                    {
                        field: 'Money', title: '钩稽金额', align: 'center', width: 60, editor: {
                            type: "numberbox",
                            options: {
                                min: 0,
                                precision: 2,
                                required: true
                            }
                        }
                    },
                    {
                        field: 'Date', title: '钩稽时间', align: 'center', width: 120, editor: {
                            type: "datebox",
                            options: {
                            }
                        }
                    }
                ]],
                columns: [[
                    {
                        field: 'RMoney', title: '回款金额 ', align: "center", width: 120, editor: {
                            type: "textbox",
                            options: {
                                editable: false
                            }
                        }
                    },
                    {
                        field: 'RDate', title: '回款时间 ', align: "center", width: 120, editor: {
                            type: "textbox",
                            options: {
                                editable: false
                            }
                        }
                    },
                    {
                        field: 'State', title: '回款状态 ', align: "center", width: 120, editor: {
                            type: "textbox",
                            options: {
                                editable: false
                            }
                        },
                        formatter: function (value, rowData, rowIndex) {
                            return com.getArrayText(StaticCombo.ReceivePayState, value)
                        }
                    },
                 {
                     field: 'Note', title: '备注', align: "center", width: 200, editor: {
                         type: "validatebox",
                         options: {
                             validType: '[length[0,250]]'
                         }
                     }
                 }
                ]],
                onAfterEdit: function (rowIndex, rowData, changes) {
                    if (editAction == "edit") {
                        com.ajax({
                            url: "/Logic/FM/InvoicePayAjax.aspx?method=EditInvoicePay",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    } else if (editAction == "add") {
                        if (invoiceID != null) {
                            rowData.InvoiceID = invoiceID;
                            com.ajax({
                                url: "/Logic/FM/InvoicePayAjax.aspx?method=AddInvoicePay",
                                data: rowData,
                                success: function (data) {
                                    com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload") });
                                }
                            });
                        } else {
                            com.message('information', '获取发票ID失败', function () { top.wrapper.tabCurrentClose() });
                        }
                    }
                    editRow = undefined;
                },
                onCancelEdit: function (rowIndex, rowData) {
                    $("#tbList").datagrid("rejectChanges");
                }
            });
        })

    </script>

    <script type="text/javascript">
        editRow = undefined;
        editAction = undefined;

        //添加
        function funcAdd() {
            //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
            if (editRow == undefined) {
                $("#tbList").datagrid("insertRow", {
                    index: 0,
                    row: {
                        Date:datetools.day(new Date())
                    }
                });
                //将新插入的那一行开户编辑状态
                $("#tbList").datagrid("beginEdit", 0);
                //给当前编辑的行赋值
                editRow = 0;
                editAction = "add";
            }
        }

        //编辑
        function funcEdit() {
            var row = $('#tbList').datagrid('getSelected');

            if (row) {
                if (editRow != undefined) {
                }
                else {
                    var index = $("#tbList").datagrid('getRowIndex', row);
                    $("#tbList").datagrid('beginEdit', index);
                    editAction = "edit";
                    editRow = index;
                    rowData = $("#tbList").datagrid("getSelected");
                }
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        //删除
        function funcRemove() {
            $.messager.confirm('确认对话框', '您确定删除该记录吗？', function (r) {
                if (r) {
                    var row = $('#tbList').datagrid('getSelected');
                    if (row) {
                        com.ajax({
                            url: "/Logic/FM/InvoicePayAjax.aspx?method=DelInvoicePay",
                            data: { Id: row.ID },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); $("#tbList").datagrid('clearSelections'); })
                            }
                        });
                    }
                    else {
                        com.message("information", "请选中一行");
                    }
                }
            });
            editRow = undefined;
            editAction = undefined;
        }

        //取消编辑
        function funcCancel() {
            $('#tbList').datagrid("cancelEdit", editRow);
            editRow = undefined;
            editAction = undefined;
        }

        //保存
        function funcSave() {
            $('#tbList').datagrid('endEdit', editRow);
        }

        //发票核销
        function funcVerify() {
            $.messager.confirm("确认对话框", "确认进行核销吗？核销完成将无法变更", function (r) {
                if (r) {
                    com.ajax({
                        url: '/Logic/FM/InvoiceAjax.aspx?method=verifyInvoice',
                        data: { 'Id': invoiceID },
                        success: function (data) {
                            com.message(data.state, data.msg, function () { top.wrapper.tabCurrentClose() })
                        }
                    })
                }
            })
        }

    </script>
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div id="divTotal" style="overflow: auto; padding: 10px; height: 100%; width: 100%">
        <div id="divToobarPD" style="background-color: #EFEFEF; overflow: visible">
            <a href="javascript:void(0)" id="btnVerify" class="easyui-linkbutton" onclick="funcVerify()"
                data-options="iconCls:'icon-book_edit',plain:true">核销完成</a>
        </div>
        <div class="container_18" style="height: auto">
            <form id="form1">
                <div id="title" class="grid_18" style="text-align: center">
                    <h1>发票信息</h1>
                    <input type="hidden" id="ID" name="ID" />
                </div>
                <div class="grid_18">
                    <hr style="width: 100%;" />
                </div>
                <div class="grid_4 lbl" style="text-align: right; margin-left: 100px">
                    客户名称 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="ComName" name="ComName" readonly="readonly" />
                </div>
                <div class="grid_4 lbl" style="text-align: right;">
                    纳税人识别号 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="TaxpayerID" name="TaxpayerID" readonly="readonly" />
                </div>
                <div class="grid_4 lbl" style="text-align: right;">
                    开户银行 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="Bank" name="Bank" readonly="readonly" />
                </div>
                <div class="grid_4 lbl" style="text-align: right;">
                    账户 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="BankAccount" name="BankAccount" readonly="readonly" />
                </div>
                <div class="Clear"></div>
                <div class="grid_4 lbl" style="text-align: right; margin-left: 100px">
                    合同名称 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="ContractID" name="ContractID" readonly="readonly" />
                </div>
                <div class="grid_4 lbl" style="text-align: right;">
                    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 合同编号 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="Code" name="Code" readonly="readonly" />
                </div>
                <div class="Clear"></div>
                <div class="grid_4 lbl" style="text-align: right; margin-left: 100px">
                    发票编号 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="InvoiceNo" name="InvoiceNo" readonly="readonly" />
                </div>
                <div class="grid_4 lbl" style="text-align: right;">
                    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 发票名称 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="InvoiceName" name="InvoiceName" readonly="readonly" />
                </div>
                <div class="grid_4 lbl" style="text-align: right;">
                    发票金额 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="Money" name="Money" readonly="readonly" />
                </div>
                <div class="grid_4 lbl" style="text-align: right;">
                    开票日期 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="Date" name="Date" readonly="readonly" />
                </div>
                <div class="Clear"></div>
                <div class="grid_4 lbl" style="text-align: right; margin-left: 100px">
                    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 备注 :
                </div>
                <div class="grid_4 val" style="text-align: left;">
                    <input type="text" id="Note" name="Note" readonly="readonly" />
                </div>
            </form>
            <div class="grid_18">
                <hr style="width: 100%;" />
            </div>
        </div>
        <div class="Clear"></div>
        <div class="divToolbar" style="background-color: #EFEFEF; overflow: visible">
            <a href="javascript:void(0)" id="btnAdd" class="easyui-linkbutton" onclick="funcAdd()"
                data-options="iconCls:'icon-save',plain:true">新增</a> &nbsp;&nbsp;
                <a href="javascript:void(0)" id="btnEdit" class="easyui-linkbutton" onclick="funcEdit()"
                    data-options="iconCls:'icon-reload',plain:true">修改</a>&nbsp;&nbsp
                <a href="javascript:void(0)" id="btnSave" class="easyui-linkbutton" onclick="funcSave()"
                    data-options="iconCls:'icon-save',plain:true">保存</a> &nbsp;&nbsp;
                <a href="javascript:void(0)" id="btnDel" class="easyui-linkbutton" onclick="funcRemove()"
                    data-options="iconCls:'icon-save',plain:true">删除</a> &nbsp;&nbsp;
                <a href="javascript:void(0)" id="btnCancel" class="easyui-linkbutton" onclick="funcCancel()"
                    data-options="iconCls:'icon-reload',plain:true">取消修改</a>
        </div>
        <div style="overflow: auto; width: 100%; height: 280px">
            <table id="tbList" title="钩稽回款列表 " style="width: 100%; height: 100%" data-options="fit:true"></table>
        </div>
    </div>
</asp:Content>
